package com.dingding.order.core.distance.biz.impl;

import java.math.BigDecimal;

import org.apache.http.HttpStatus;
import org.springframework.stereotype.Component;

import com.dingding.common.core.base.dto.ResponseEntity;
import com.dingding.common.core.util.dto.CalculatDistanceDTO;
import com.dingding.order.core.distance.biz.ICalculateDistanceService;
import com.dingding.order.core.distance.biz.abstracts.AbstractCalculatDistance;
import com.dingding.order.dto.distance.ReqCalculateDistanceDTO;
import com.dingding.order.dto.distance.ReqTaxiCalculateDistanceDTO;
import com.dingding.order.dto.distance.ResTaxiCalculateDistance;

/**
 * 
 * @ClassName: TaxiCalculateDistanceServiceImpl
 * @Description: 出租车计算距离业务处理类
 * @author CHEHAUNBO
 * @date 2016年6月29日 下午3:33:45
 * @since V2.3.0
 * 
 */
@Component("taxiDistanceService")
public class TaxiCalculateDistanceServiceImpl
		extends AbstractCalculatDistance<ResTaxiCalculateDistance, ReqTaxiCalculateDistanceDTO>
		implements ICalculateDistanceService {

	/**
	 * @Title: calculateDistance
	 * @Description:出租车计算距离
	 * @author CHEHUANBO
	 * @since V2.3.0
	 * 
	 * 修改人：周璇
	 * 修改原因：加入出租车业务
	 * 修改时间：2016/6/30
	 * 修改版本：V2.3.0
	 * 
	 * 修改人：车焕波
	 * 修改原因：计算距离方法将变量变为对象
	 * 修改时间：2016-07-18
	 * 修改版本：V2.3.1
	 * 
	 */
	@Override
	public String calculateDistance(String requestJson) {

		ReqTaxiCalculateDistanceDTO reqTaxiCalculateDistanceDTO = super.parseRequestJson(requestJson);

		ResponseEntity<ResTaxiCalculateDistance> response = new ResponseEntity<ResTaxiCalculateDistance>();

		// 1:验证请求参数
		if (!super.validateParam(response, reqTaxiCalculateDistanceDTO)) {
			return super.responseBeanToJson(response);
		}
		// 2:计算距离
		CalculatDistanceDTO calculatDistanceDTO = super.distance(reqTaxiCalculateDistanceDTO.getStartLongitude(),
				reqTaxiCalculateDistanceDTO.getStartLatitude(), reqTaxiCalculateDistanceDTO.getEndLongitude(),
				reqTaxiCalculateDistanceDTO.getEndLatitude());
		// 3:拼装响应
		assemblyContent(response, calculatDistanceDTO.getDistance());

		return super.responseBeanToJson(response);

	}

	/**
	 * @Title: assemblyContent
	 * @Description:封装响应
	 * @author zhouxuan
	 * @return ResTaxiCalculateDistance
	 */
	private ResTaxiCalculateDistance assemblyContent(ResponseEntity<ResTaxiCalculateDistance> response,
			BigDecimal distance) {
		ResTaxiCalculateDistance resTaxiCalculateDistance = new ResTaxiCalculateDistance();
		resTaxiCalculateDistance.setDistance(distance); // 距离
		response.setCode(HttpStatus.SC_OK);
		response.setResponseBody(resTaxiCalculateDistance);
		return resTaxiCalculateDistance;
	}

	@Override
	public BigDecimal calcDistanceCost(ReqCalculateDistanceDTO dto) {
		return null;
	}
}
